<?php 
	
	if(!empty($_POST))
	{
				
		$signup->process_form();

	}

 if(empty($_SESSION['user_level'])){
  if(empty($_GET['login'])){
 ?>

<form class="form-class" action="signup" id="signup" method="post">
	<div class='c-box-600 c-box c-box-left' id='signup'>
		<h1 style='text-align:left; text-decoration:underline; font-size:1.5em; margin-bottom:20px;'>Pinoytuner Sign-up</h1>
		<div class="row">
			<div class="left">username</div>
			<div class="right"><input type="text" name="uname" id="uname" /><span style="display:none" id='loading2'><image style="vertical-align:middle" src='assets/images/ajax-loader.gif'></span></div>
			<div class="clear"></div>
		</div>
		<div class="row">
			<div class="left">email</div>
			<div class="right"><input type="text" name="email" id="email" /><span style="display:none" id='loading'><image style="vertical-align:middle" src='assets/images/ajax-loader.gif'></span></div>
			<div class="clear"></div>
		</div>
		<input type="button" id='signup-button' value="sign up">	
		<input type="hidden" id='emailvalid' value="no">
		<input type="hidden" id='usernamevalid' value="no">		
		<hr />
		already have an account? <a href='signup?login=1'>Login</a> to Pinoytuner.
	</div>
</form>


	<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){	
		
		$("#email").blur(function(){
		$('#loading').css('display','inline');	
			var email = $(this).val();
			var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
			var validemail =  pattern.test(email);
			
			if(validemail)
			{
			
			
			  $.ajax({
					
						type: "POST",
						url: "admin/a/email_exists_check.php",
						data: {'user_email':email},
						dataType: "json",
						success: function(data) 
						{
						$('#loading').html(data.text);	
						if(data.valid)
							$('#emailvalid').attr('value','yes');
						else
							$('#emailvalid').attr('value','no');
						}
				});
			}
			else
			{
				$('#loading').html("<img src=assets/images/eks.png height=20 width=20 style='vertical-align:middle' > invalid email format");	
			}			
		});
		$("#uname").blur(function(){
		$('#loading2').css('display','inline');	
			var uname = $(this).val();
		
			  $.ajax({
					
						type: "POST",
						url: "admin/a/username_exists_check.php",
						data: {'user_name':uname},
						dataType: "json",
						success: function(data) 
						{
						$('#loading2').html(data.text);	
						if(data.valid)
							$('#usernamevalid').attr('value','yes');
						else
							$('#usernamevalid').attr('value','no');	
						}
				});
			}
					
		);
		$("#signup-button").click(function(){
		
			
			if($("#emailvalid").attr('value') == "yes" && $("#usernamevalid").attr('value') == "yes")
					$("form").submit();
			
			else
				alert("fill out invalid fields properly");
		});
	});
	</script>
	
<?php
	}
	else
	{
	?>
	<form class="form-class" action="a/process-login.php" id="signup" method="post">
			
			<div class='c-box-600 c-box c-box-left' id='signup'>
				<h1 style='text-align:left; text-decoration:underline; font-size:1.5em; margin-bottom:20px;'>Login to Pinoytuner</h1>
				
				<div class="row">
					<div class="left">username</div>
					<div class="right"><input type="text" name="user_name" id="user_name"/></div>
					<div class="clear"></div>
				</div>
				<div class="row">
					<div class="left">password</div>
					<div class="right"><input type="password" name="user_password" id="user_password" /></div>
					<div class="clear"></div>
				</div>
				<input type="hidden"  name ='login-form' value="login-form">
				<input type="submit"  value="login">	
				<hr />
				Not Registerd with Pinoytuner Yet? <a href='signup/new-user'>Sign-up</a>.
				<?php
				if(isset($_GET['success']))
				{
					if($_GET['success']==0)
						echo "<hr>	Invalid Login";
					else
						header("location:#");
				}
				?>
	</div>
	</form>
		<?php
	}
	
}
else
{
?>
	<div class='c-box-600 c-box c-box-left' id='signup'>
		<h1 style='text-align:left; text-decoration:underline; font-size:1.5em; margin-bottom:20px;'>Change Password</h1>
		<div class="row">
			<div class="left">current-password</div>
			<div class="right"><input type="password" name="cpass" id="cpass" /></div>
			<div class="clear"></div>
		</div>
		<div class="row">
			<div class="left">new-password</div>
			<div class="right"><input type="password" name="npass" id="npass" /></div>
			<div class="clear"></div>
		</div>
		<div class="row">
			<div class="left">retype-new-password</div>
			<div class="right"><input type="password" name="npass2" id="npass2" /></div>
			<div class="clear"></div>
		</div>
		<input type="button" id='cp' value="change password">	


	</div>	
	
	<script type="text/javascript" charset="utf-8">
		$(document).ready(function(){
		$("#cp").click(function(){
			var uname = $(this).val();
			var cpass = $("#cpass").val();
			var npass = $("#npass").val();
			var npass2 = $("#npass2").val();
			  $.ajax({
					
						type: "POST",
						url: "admin/a/process-password.php",
						data: {'user_password':cpass,'new-pass':npass,'new-pass2':npass2},
						dataType: "json",
						success: function(data) 
						{
							alert(data.text);
						}
				});
			}
					
		);
		
		
		});
	</script>
<?php
}
?>	